import 'package:inmotion_pro/service/realtime_data_server/realtime_data_service.dart';
import 'package:inmotion_pro/service/realtime_data_server/vehicle_realtime_data/vehicle_realtime_info.dart';
import 'package:inmotion_pro/service/realtime_data_server/vehicle_realtime_data/vehicle_realtime_status.dart';

class TestRealTimeDataService extends RealTimeDataService {
  final Map<String, int> activeCounts = {};
  final Map<String, int> maxConcurrent = {};

  Future<T> _track<T>(String tag, Future<T> Function() fn) async {
    activeCounts[tag] = (activeCounts[tag] ?? 0) + 1;
    maxConcurrent[tag] = (maxConcurrent[tag] ?? 0) < (activeCounts[tag] ?? 0)
        ? (activeCounts[tag] ?? 0)
        : (maxConcurrent[tag] ?? 0);
    try {
      // 模拟网络/蓝牙请求的耗时
      await Future.delayed(const Duration(milliseconds: 100));
      return await fn();
    } finally {
      activeCounts[tag] = (activeCounts[tag] ?? 1) - 1;
    }
  }

  @override
  Future<VehicleRealtimeInfo> protocolMixinGetRealtimeInfo() {
    return _track('realtimeInfo', () async {
      return VehicleRealtimeInfo.fromMap({});
    });
  }

  @override
  Future<VehicleRealtimeStatus> protocolMixinGetRealtimeStatus() {
    return _track('realtimeStatus', () async {
      return VehicleRealtimeStatus.fromMap({});
    });
  }
}

void main() {}
